new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Warehouse_Name: "",
                Article_Name: "",
                page: 1,			//页数
                limit: 10,			//每页数据条数
                Row_Status: '',
            },
            Row_Status: [
                {//发货订单状态
                    label: '全部',
                    value: ''
                },
                {
                    label: '待发货',
                    value: '0'
                },
                {
                    label: '已发货',
                    value: '1'
                },
                {
                    label: '已送达',
                    value: '2'
                }
            ],
            tableData: [],
            Wares: [],
            total: 1,
            loading: false,
            enterprise:$.cookie("enterprise")
        }
    },
    mounted() {
        this.getList(this.form)
    },
    methods: {
        ChangeWarehouse(e) {
            this.form.page = 1
            this.form.Warehouse_Name = e
            this.getList(this.form)
        },
        ChangeRowStatus(e) {
            this.form.page = 1
            this.form.Row_Status = e
            this.getList(this.form)
        },
        onSerach() {
            this.form.page = 1
            this.getList(this.form)
        },
        handleSizeChange(val) {
            this.form.page = 1;
            this.form.limit = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.page = val;
            this.getList(this.form)
        },
        getList(data) {//获取所有发货订单
            console.log('测试',sessionStorage.getItem('RoleArr'))
            let _this = this
            $.ajax({
                type: 'POST',
                url: DomainName + "/getDeliveryOrderAllAction?token=" + $.cookie("token"),
                data,
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (Result) {
                    console.log(Result);
                    _this.tableData = Result.tableData      //将获取的数据存到表格数据中
                    _this.total = parseInt(Result.limit)
                },

                dataType: "json"
            });
        },
        handleSelectionChange(val) {
            this.multipleSelection = val; 
            console.log(this.multipleSelection);
        },
        Shipments(row) {//发货 
            console.log('上个页面传过来的',JSON.stringify(row)) 
            console.log('ceshi',encodeURIComponent(JSON.stringify(row)));
            let _this = this
            //调出弹窗填写物流单号
            sessionStorage.setItem('fillorder', JSON.stringify(row)) 
            window.location.href = './SalesOutboundOrder.html?fillorder='+encodeURIComponent(JSON.stringify(row)) 
        },
        SubmitChange(row, Row_Status, message = '成功') {//修改查到的原值并提交
            row.Row_Status = Row_Status
            console.log(row)
            let _this = this
            $.ajax({
                type: 'POST',
                url: DomainName + "getAddAction?token=" + $.cookie("token"),
                data: {
                    Data: JSON.stringify({
                        delivery_order: [row]
                    })
                },
                success: function (res) {
                    console.log(res)
                    if (res.Status == 'success') {
                        _this.$message({
                            message,
                            type: 'success'
                        });
                        _this.loading = false
                        _this.getList(_this.form)
                    }
                },
                complete: function (XMLHttpRequest) {
                    _this.loading = false
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        }
    },
})